home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Graphics 3D / RaveContextSample / Source / Misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  2.1 KB  |  123 lines  |  [TEXT/CWIE]

  1. /****************************/
  2. /*      MISC ROUTINES       */
  3. /* By Brian Greenstone      */
  4. /****************************/
  5.  
  6.  
  7. /***************/
  8. /* EXTERNALS   */
  9. /***************/
  10. #include <Events.h>
  11. #include <Dialogs.h>
  12. #include <Processes.h>
  13. #include <NumberFormatting.h>
  14. #include <math.h>
  15.  
  16. #include <QD3D.h>
  17. #include <QD3DErrors.h>
  18.  
  19. #include "myglobals.h"
  20. #include "misc.h"
  21.  
  22. extern    EventRecord    gTheEvent;
  23.  
  24.  
  25. /****************************/
  26. /*    CONSTANTS             */
  27. /****************************/
  28.  
  29. #define        ERROR_ALERT_ID        401
  30.  
  31. /**********************/
  32. /*     VARIABLES      */
  33. /**********************/
  34.  
  35. unsigned long seed0 = 0, seed1 = 0, seed2 = 0;
  36. unsigned long seed0_alt = 0, seed1_alt = 0, seed2_alt = 0;
  37.  
  38.  
  39. /****************** DO SYSTEM ERROR ***************/
  40.  
  41. void ShowSystemErr(long err)
  42. {
  43. Str255        numStr;
  44.  
  45.     NumToString(err, numStr);
  46.     DoAlert (numStr);
  47.     CleanQuit();
  48. }
  49.  
  50. /*********************** DO ALERT *******************/
  51.  
  52. void DoAlert(Str255 s)
  53. {
  54.     ParamText(s,NIL_STRING,NIL_STRING,NIL_STRING);
  55.     NoteAlert(ERROR_ALERT_ID,nil);
  56. }
  57.         
  58. /*********************** DO FATAL ALERT *******************/
  59.  
  60. void DoFatalAlert(Str255 s)
  61. {
  62.     ParamText(s,NIL_STRING,NIL_STRING,NIL_STRING);
  63.     NoteAlert(ERROR_ALERT_ID,nil);
  64.     CleanQuit();
  65. }
  66.  
  67. /************ CLEAN QUIT ***************/
  68.  
  69. void CleanQuit(void)
  70. {
  71.     ExitToShell();
  72. }
  73.  
  74.  
  75.  
  76.  
  77. /******************** MY RANDOM LONG **********************/
  78. //
  79. // My own random number generator that returns a LONG
  80. //
  81. // NOTE: call this instead of MyRandomShort if the value is going to be
  82. //        masked or if it just doesnt matter since this version is quicker
  83. //        without the 0xffff at the end.
  84. //
  85.  
  86. static unsigned long MyRandomLong(void)
  87. {
  88.   return seed2 ^= (((seed1 ^= (seed2>>5)*1568397607UL)>>7)+
  89.                    (seed0 = (seed0+1)*3141592621UL))*2435386481UL;
  90. }
  91.  
  92.  
  93. /************** RANDOM FLOAT ********************/
  94. //
  95. // returns a random float between 0 and 1
  96. //
  97.  
  98. float RandomFloat(void)
  99. {
  100. unsigned long    r;
  101. float    f;
  102.  
  103.     r = MyRandomLong() & 0xfff;        
  104.     if (r == 0)
  105.         return(0);
  106.  
  107.     f = (float)r;                            // convert to float
  108.     f = f / (float)0xfff;                    // get # between 0..1
  109.     return(f);
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.